#下载eSDK-CSI依赖的sidecar镜像
docker pull registry.aliyuncs.com/google_containers/livenessprobe:v2.12.0
docker pull registry.aliyuncs.com/google_containers/csi-resizer:v1.9.0
docker pull registry.aliyuncs.com/google_containers/csi-node-driver-registrar:v2.9.0
docker pull registry.aliyuncs.com/google_containers/csi-snapshotter:v6.3.0
docker pull registry.aliyuncs.com/google_containers/snapshot-controller:v6.3.0
docker pull registry.aliyuncs.com/google_containers/csi-provisioner:v3.6.0
docker pull registry.aliyuncs.com/google_containers/csi-attacher:v4.4.0

#重新打tag
docker tag registry.aliyuncs.com/google_containers/livenessprobe:v2.12.0                         registry.k8s.io/sig-storage/livenessprobe:v2.12.0
docker tag registry.aliyuncs.com/google_containers/csi-resizer:v1.9.0                                   registry.k8s.io/sig-storage/csi-resizer:v1.9.0
docker tag registry.aliyuncs.com/google_containers/csi-node-driver-registrar:v2.9.0        registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.9.0
docker tag registry.aliyuncs.com/google_containers/csi-snapshotter:v6.3.0                         registry.k8s.io/sig-storage/csi-snapshotter:v6.3.0
docker tag registry.aliyuncs.com/google_containers/snapshot-controller:v6.3.0                 registry.k8s.io/sig-storage/snapshot-controller:v6.3.0
docker tag registry.aliyuncs.com/google_containers/csi-provisioner:v3.6.0                          registry.k8s.io/sig-storage/csi-provisioner:v3.6.0
docker tag registry.aliyuncs.com/google_containers/csi-attacher:v4.4.0                                registry.k8s.io/sig-storage/csi-attacher:v4.4.0

#导出为离线的tar包，并把依赖的镜像打成一个eSDK_Huawei_Storage_Kubernetes_CSI_Plugin_dependency.tar包
CSI_Plugin_Path=eSDK_Huawei_Storage_Kubernetes_CSI_Plugin_dependency
mkdir $CSI_Plugin_Path
docker save registry.k8s.io/sig-storage/livenessprobe:v2.12.0  -o ${CSI_Plugin_Path}/livenessprobe.tar
docker save registry.k8s.io/sig-storage/csi-resizer:v1.9.0  -o ${CSI_Plugin_Path}/csi-resizer.tar
docker save registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.9.0 -o ${CSI_Plugin_Path}/csi-node-driver-registrar.tar
docker save registry.k8s.io/sig-storage/csi-snapshotter:v6.3.0 -o ${CSI_Plugin_Path}/csi-snapshotter.tar
docker save registry.k8s.io/sig-storage/snapshot-controller:v6.3.0 -o ${CSI_Plugin_Path}/snapshot-controller.tar
docker save registry.k8s.io/sig-storage/csi-provisioner:v3.6.0  -o ${CSI_Plugin_Path}/csi-provisioner.tar
docker save registry.k8s.io/sig-storage/csi-attacher:v4.4.0  -o ${CSI_Plugin_Path}/csi-attacher.tar
tar -cvf eSDK_Huawei_Storage_Kubernetes_CSI_Plugin_dependency.tar eSDK_Huawei_Storage_Kubernetes_CSI_Plugin_dependency/

#从github下载eSDK-CSI配套版本的包
wget --no-check-certificate https://github.com/Huawei/eSDK_K8S_Plugin/releases/download/v4.9.0/eSDK_Storage_CSI_V4.9.0_ARM_64.zip
unzip eSDK_Storage_CSI_V4.9.0_ARM_64.zip
mv eSDK_Storage_CSI_V4.9.0_ARM_64 eSDK_Huawei_Storage_Kubernetes_CSI_Plugin_V4.9.0_ARM_64

#下载安装helm，用于把eSDK-CSI打包成Chart包
wget --no-check-certificate https://get.helm.sh/helm-v3.10.3-linux-arm64.tar.gz
tar -zxvf helm-v3.10.3-linux-arm64.tar.gz
mv -f linux-arm64/helm /usr/bin/
helm package eSDK_Huawei_Storage_Kubernetes_CSI_Plugin_V4.9.0_ARM_64/helm/esdk

#从CSI软件包中加载配套的镜像，并重新导出为离线的tar包
docker load -i eSDK_Huawei_Storage_Kubernetes_CSI_Plugin_V4.9.0_ARM_64/image/huawei-csi-v4.9.0-arm.tar
docker load -i eSDK_Huawei_Storage_Kubernetes_CSI_Plugin_V4.9.0_ARM_64/image/storage-backend-controller-v4.9.0-arm.tar
docker load -i eSDK_Huawei_Storage_Kubernetes_CSI_Plugin_V4.9.0_ARM_64/image/storage-backend-sidecar-v4.9.0-arm.tar
docker load -i eSDK_Huawei_Storage_Kubernetes_CSI_Plugin_V4.9.0_ARM_64/image/huawei-csi-extender-v4.9.0-arm.tar
rm -rf eSDK_Huawei_Storage_Kubernetes_CSI_Plugin_V4.9.0_ARM_64/image/*
docker save -o eSDK_Huawei_Storage_Kubernetes_CSI_Plugin_V4.9.0_ARM_64/image/huawei-csi-v4.9.0-arm.tar huawei-csi:4.9.0
docker save -o eSDK_Huawei_Storage_Kubernetes_CSI_Plugin_V4.9.0_ARM_64/image/storage-backend-controller-v4.9.0-arm.tar storage-backend-controller:4.9.0
docker save -o eSDK_Huawei_Storage_Kubernetes_CSI_Plugin_V4.9.0_ARM_64/image/storage-backend-sidecar-v4.9.0-arm.tar storage-backend-sidecar:4.9.0
docker save -o eSDK_Huawei_Storage_Kubernetes_CSI_Plugin_V4.9.0_ARM_64/image/huawei-csi-extender-v4.9.0-arm.tar huawei-csi-extender:4.9.0

#把eSDK-CSI打包为eSDK_Huawei_Storage_Kubernetes_CSI_Plugin_V4.9.0_ARM_64.tar
tar -cvf eSDK_Huawei_Storage_Kubernetes_CSI_Plugin_V4.9.0_ARM_64.tar eSDK_Huawei_Storage_Kubernetes_CSI_Plugin_V4.9.0_ARM_64/

#构建最外层的包，将以上打的两个包（依赖镜像+eSDK-CSI软件包）打成一个最终的包
mkdir huawei_csi_install_package_arm
mv  esdk-4.9.0.tgz huawei_csi_install_package_arm
mv  eSDK_Huawei_Storage_Kubernetes_CSI_Plugin_dependency.tar huawei_csi_install_package_arm
mv  eSDK_Huawei_Storage_Kubernetes_CSI_Plugin_V4.9.0_ARM_64.tar huawei_csi_install_package_arm
tar -cvf huawei_csi_install_package_arm.tar huawei_csi_install_package_arm/
rm -rf eSDK_Storage_CSI* helm-v3.10.3-linux-arm64.tar.gz huawei_csi_install_package_arm linux-arm64